package com.ruoyi.common.utils;

/**
 * @author wx
 * @Package com.ruoyi.common.utils
 * @date 2025-08-14 14:05
 */

import com.github.pagehelper.Page;
import com.github.pagehelper.dialect.AbstractHelperDialect;
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;

import java.util.List;
import java.util.Map;

public class FirebirdDialect extends AbstractHelperDialect {


    @Override
    public Object processPageParameter(MappedStatement mappedStatement, Map<String, Object> map, Page page, BoundSql boundSql, CacheKey cacheKey) {
        return map;
    }

    @Override
    public String getPageSql(String s, Page page, CacheKey cacheKey) {
        // 页起始行号
        long offset = page.getStartRow();       // PageHelper 内部计算的起始行，从 0 开始
        long limit = page.getPageSize();        // 每页条数

        long start = offset + 1;                // Firebird 从 1 开始
        long end = offset + limit;

        return s + " ROWS " + start + " TO " + end;
    }
}
